package com.party.mobile.web.interceptor;

import com.party.mobile.redisPubSub.subscribe.SubScribeMessage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @Description: spring容器初始化完成后自动执行的类
 * @Author: yangshoukun
 * @Date: 2018/4/2 14:40
 */
@Component
public class SupportTransferListener implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        // spring容器可以有多个ApplicationContext，例如spring MVC就存在一个ApplicationContext，但是根ApplicationContext却只有一个
        if(event.getApplicationContext().getParent() == null ) {
            ApplicationContext applicationContext = event.getApplicationContext();
            SubScribeMessage subScribeMessage = applicationContext.getBean("subScribeMessage", SubScribeMessage.class);
            subScribeMessage.subscribeChannel("projectTansferMobile");
        }
    }
}

